<template>
	<view class="rank">
		<view class="rank-item" v-for="(item,index) in rank" :key="item.id">
			<view class="pics">
				<view>
					<view class="flag">
						<text class="no" :style="index>8?'fontsize:14px':'margin-left:5px'">{{ index+1 }}</text>
						<image class="f-icon" v-show="index===0" src="../../static/icons/NO1.png"></image>
					</view>
					<image class="f-icon" v-show="index===1" src="../../static/icons/NO2.png"></image>
					<image class="f-icon" v-show="index===2" src="../../static/icons/NO3.png"></image>
					<image class="f-icon" v-show="index>2" src="../../static/icons/NO.png"></image>
					<image class="cover" :src="item.cover_url" @click="goDetail(item.id)"></image>
				</view>
				<swiper class="swiper" indicator-dots  @click="goDetail(item.id)">
					<swiper-item v-for="(item,index) in item.pics" :key="index">
						<view class="swiper-item">
							<image :src="item.img_url" ></image>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<view class="text">
				<!-- <view class="t-tit">
					<view class="like">
						<uni-icons :type="flag[index]?'heart-filled':'heart'" size="30px" color="#ff9500" @click="collect(index)"></uni-icons>
						<view style="color: #ff9500;">想看</view>
					</view>
				</view> -->
				<view class="b">{{ item.title }}</view>
				<view class="t-score">
					<uni-rate :readonly="true" :value="item.grade*0.5" size="13px"/>
					<view class="t-score-n" style="color: #ff9500;">{{ item.grade }}</view>
				</view>
				<view class="s">{{ item.tag }}</view>
				<view class="t-intro">
					<rich-text :nodes="item.intro"></rich-text>
				</view>
			</view>
		</view>
		<!-- 底部区域 -->
		<view class="bottom" v-show="rankflag">前面的区域以后再来探索吧</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageIndex: 0,
				rankflag: false,
				flag: [],
				rank: []
			}
		},
		onLoad() {
			this.getRank()
			// console.log(this.rank)
		},
		onReachBottom() {
			// console.log('触底了')
			this.pageIndex++
			this.getRank()
		},
		methods: {
			getRank() {
				uni.request({
					url: 'http://www.yingke.com/Index/ranking?page='+this.pageIndex,
					method: 'POST',
					success: (res) => {
						if(res.data.data.length==0){
							this.rankflag = true
						}
						else{
							this.rank = [...this.rank,...res.data.data]
						}
					}
				})
			},
			goDetail(id){//跳转至影片详情页
				uni.navigateTo({
					url: '../mov-detail/mov-detail?data='+id
				})
			},
			collect(index) {
				if(this.flag[index]){
					this.flag[index] = 0
					//收藏表中删除该项
				}
				else{
					this.flag[index] = 1
					//收藏表中增加该项
				}
				// console.log(this.flag)
				this.$forceUpdate()
				//将对应id的影片加入收藏数组
			}
		}
	}
</script>

<style lang="scss">
	.rank{
		margin-left: 10px;
		.rank-item{
			padding-bottom: 10px;
			border-bottom: 1px solid #eaeaea;
			.pics{
				display: flex;
				margin-top: 10px;
				.flag{
					.no{
						position: absolute;
						z-index: 2;
						font-size: 18px;
						color: #fff;
					}
				}
				.f-icon{
					width: 30px;
					height: 30px;
					position: absolute;
					z-index: 1;
					margin-left: -4px;
					margin-top: -2px;
				}
				.cover{
					width: 110px;
					height: 160px;
					border-radius: 10px;
				}
				.swiper{
					width: 65%;
					height: 160px;
					margin-left: 15px;
					image{
						width: 235px;
						height: 160px;
						border-radius: 10px;
					}
				}
			}
			.text{
				margin-top: 10px;
				.t-tit{
					.like{
						margin-right: 10px;
						float: right;
						text-align: center;
					}
				}
				.t-score{
					display: inline-flex;
					.t-score-n{
						position: absolute;
						left: 75px;
						margin-top: -5px;
						font-size: 15px;
					}
				}
				.t-intro{
					height: 85px;
					overflow: hidden;
				}
			}
		}
		.bottom{
			height: 50px;
			margin-top: 20px;
			text-align: center;
		}
	}
</style>
